package cn.glow.readingcloud.homepage.service.impl;


import cn.glow.readingcloud.book.feign.client.BookClient;
import cn.glow.readingcloud.common.pojo.Book;
import cn.glow.readingcloud.homepage.service.BookCenterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

/**
 * @Author Glow
 * @Date 2023-04-17 23:06:03
 * @Description 其实就是再一次feign调用book服务的封装实现罢了
 * @Version 1.0
 */
@Service
public class BookCenterServiceImpl implements BookCenterService {
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private BookClient bookClient;
    @Override
    public Book getBookById(String bookId) {
        Book book = (Book) redisTemplate.opsForValue().get("bookDetail:"+bookId);
        if(book == null)
        {
         book =  bookClient.getBookById(bookId).getData();
                redisTemplate.opsForValue().set("bookDetail:"+bookId,book);
        }
        return  book;
    }
}
